const fs = require("fs");

const data = "我是从数据库获取的数据，我现在需要保存下来。";

const writeStream = fs.createWriteStream("output.txt");


for (let i = 0; i < 100; i++) {
    var write = writeStream.write(data, "utf8");
}

//标志写入完成
writeStream.end();

writeStream.on("finish", function () {

    console.log("写入完成");
});

writeStream.on("error", function () {

    console.log("写入失败");
});